#include <cs50.h>
#include <ctype.h>
#include <stdio.h>

//第一个由自己完成的全绿练习题

float calc_hours(int hours[], int weeks, char output);

int main(void)
{
    // 1.获取学习CS50的周数
    int weeks = get_int("Number of weeks taking CS50: ");
    int hours[weeks];

    for (int i = 0; i < weeks; i++)
    {
        // 2.获取每周学习CS50的小时数
        hours[i] = get_int("Week %i HW Hours: ", i);
    }

    char output;
    do
    {
        // 3.做总值和均值的选择
        output = toupper(get_char("Enter T for total hours, A for average hours per week: "));
    }
    while (output != 'T' && output != 'A');

    printf("%.1f hours\n", calc_hours(hours, weeks, output));
}
// debug50

// TODO: complete the calc_hours function
float calc_hours(int hours[], int weeks, char output)
{
    float result = 0;

    if (output == 'T')
    {
        for (int j = 0; j < weeks; j++)
        {
            result = result + hours[j];
        }
        return result;
    }
    else if (output == 'A')
    {
        for (int j = 0; j < weeks; j++)
        {
            result = result + hours[j];
        }
        return (result / weeks);
        printf("%d\n", weeks);
    }

    return 0;
}


